package com.geeyuu.android.activity;

import java.util.ArrayList;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ListView;

import com.geeyuu.android.R;
import com.geeyuu.android.model.BaseUserInfo;
import com.geeyuu.android.utils.AndroidUtil;

public class PersonListActivity extends BaseActivity {
    
    public static final String EXTRA_TYPE = "personType";
    public static final int TYPE_MY_ATTENTION = 0;
    public static final int TYPE_ACTTENTION_ME = 1;
    public static final int TYPE_LOOKED_ME = 2;
    private int type;
    
    private ListView mListView;
    private BaseAdapter mPersionListAdatper;
    private ArrayList<BaseUserInfo> userInfos;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.persion_list_layout);
        
        type = getIntent().getIntExtra(EXTRA_TYPE, -1);
        if(type == TYPE_MY_ATTENTION){
            
        }else if(type == TYPE_ACTTENTION_ME){
            
        }else if(type == TYPE_LOOKED_ME){
            
        }else {
            finish();
            return;
        }
        
        initTitleViews();
        initContentViews();
        
    }

    private void initTitleViews() {
        Button topLeftButton = (Button)findViewById(R.id.top_left_button);
        topLeftButton.setVisibility(View.VISIBLE);
        topLeftButton.setOnClickListener(mOnClickListener);
        if(type == TYPE_MY_ATTENTION){
            topLeftButton.setText("我关注的");
            topLeftButton.setCompoundDrawablesWithIntrinsicBounds(R.drawable.my_attention_title_icon, 0, 0, 0);
        }else if(type == TYPE_ACTTENTION_ME){
            topLeftButton.setText("关注我的");
            topLeftButton.setCompoundDrawablesWithIntrinsicBounds(R.drawable.attention_me_title_icon, 0, 0, 0);
        }else if(type == TYPE_LOOKED_ME){
            topLeftButton.setText("访问我的");
            topLeftButton.setCompoundDrawablesWithIntrinsicBounds(R.drawable.looked_me_title_icon, 0, 0, 0);
        }
        topLeftButton.setPadding(AndroidUtil.dip2px(this, 10), 0, 0, 0);
        ViewGroup.LayoutParams vl = topLeftButton.getLayoutParams();
        if(null == vl){
            vl = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.FILL_PARENT);
        }else{
            vl.width = ViewGroup.LayoutParams.WRAP_CONTENT;
            vl.height = ViewGroup.LayoutParams.FILL_PARENT;
        }
        topLeftButton.setLayoutParams(vl);
    }

    private void initContentViews() {
        userInfos = new ArrayList<BaseUserInfo>();
        for(int i=0; i<10; i++){
            BaseUserInfo ui = new BaseUserInfo();
            userInfos.add(ui);
        }
        
        mListView = (ListView)findViewById(R.id.persion_listview);
        mPersionListAdatper = new PersionListAdatper();
        mListView.setAdapter(mPersionListAdatper);
    }
    
    private class PersionListAdatper extends BaseAdapter {
        
        private int dataCount = 0;
        
        public PersionListAdatper(){
            dataCount = userInfos.size();
        }
        @Override
        public int getCount() {
            return dataCount;
        }
        @Override
        public Object getItem(int position) {
            return null;
        }
        @Override
        public long getItemId(int position) {
            return 0;
        }
        @Override
        public void notifyDataSetChanged() {
            dataCount = userInfos.size();
            super.notifyDataSetChanged();
        }
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View view = convertView;
            if(view == null){
                view = getLayoutInflater().inflate(R.layout.friend_list_item, parent, false);
            }
            return view;
        }
        
    }
    
    private OnClickListener mOnClickListener = new OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
            case R.id.top_left_button:
                finish();
                break;
            }
        }
    };
    
}
